package nl.ceasaro.jeslee.webapp.stock.action;

import com.opensymphony.xwork2.Action;
import org.apache.struts2.config.Namespace;
import org.apache.struts2.config.NullResult;
import org.apache.struts2.config.Result;
import org.apache.struts2.views.tiles.TilesResult;
import org.springframework.stereotype.Component;
import nl.ceasaro.jeslee.core.stock.DressService;
import nl.ceasaro.jeslee.core.model.clothes.Dress;

import javax.annotation.Resource;
import java.util.Collection;

/**
 * Created by IntelliJ IDEA.
 * User: cees
 * Date: Oct 17, 2008
 * Time: 9:02:57 PM
 * <p>
 * This struts action class is responsible CRUD-actions on dresses.
 * </p>
 */
@Component
@Namespace(value = "/stock")
@Result(name = Action.SUCCESS,
      value = "stock.dresses",
      type = TilesResult.class)
public class DressesAction extends AbstractStockAction
{
   private static final long serialVersionUID = 1777128636351823195L;
   private Collection<Dress> dresses;
   private int dressCount;

   @Override
   public String execute() throws Exception
   {
      Collection<Dress> dressCollection = getDressService().findAll();
      setDresses(dressCollection);
      setDressCount(dressCollection.size());
      return SUCCESS;
   }

   public Collection<Dress> getDresses()
   {
      return dresses;
   }

   public void setDresses(Collection<Dress> dresses)
   {
      this.dresses = dresses;
   }

   public int getDressCount()
   {
      return dressCount;
   }

   public void setDressCount(int dressCount)
   {
      this.dressCount = dressCount;
   }/*
   * ******************************************
   * Spring injections
   * ******************************************
   */
   private DressService dressService;

   public DressService getDressService()
   {
      return dressService;
   }

   @Resource
   public void setDressService(DressService dressService)
   {
      this.dressService = dressService;
   }
}
